package smashedapples.air.sqlite.commands
{
	import flash.data.SQLStatement;
	import flash.events.SQLErrorEvent;
	import flash.events.SQLEvent;
	
	import smashedapples.air.sqlite.SQLiteDB;
	import smashedapples.air.sqlite.events.SQLiteDeleteEvent;
	import smashedapples.air.sqlite.responses.SQLiteDeleteResponse;
	
	[Event(name="Delete",type="smashedapples.air.sqlite.events.SQLiteDeleteEvent")]
	
	public class SQLiteDeleteCommand extends SQLiteBaseCommand
	{
		public function SQLiteDeleteCommand( db:SQLiteDB, 
											 tableName:String, 
											 parameters:Object = null,
											 result:Function = null, 
											 fault:Function = null )
		{
			super( db, tableName, parameters, result, fault );	
					
		}
		
		
		
		public function resultHandler( event:SQLEvent ):void
		{	
			
			// pull out the statement
			var statement:SQLStatement = event.target as SQLStatement;

			// create response
			var response:SQLiteDeleteResponse = new SQLiteDeleteResponse( this.table, this.parameters );
						
			// invoke response
			if( this.result != null )
				result( response );
			
			
			db.dispatchEvent( new SQLiteDeleteEvent( response ) );
		}
		
		public function faultHandler( event:SQLErrorEvent ):void
		{
			this.db.addToDebug( event );
		}
		
	}
}